/**
 * 
 */
package com.gwcloud.leetcode.offers;

import java.util.HashMap;

import com.gwcloud.leetcode.common.datastructure.ListNode;

/**
 * @ClassName   : Leetcode0520 
 * @author      : ganwei 
 * @date        : 2020年6月6日
 * @Description : Leetcode0520
 */
public class Leetcode0520 {
    /**
     * -解题思路，Hash表
     */
	public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        HashMap<ListNode, Integer> map = new HashMap<ListNode, Integer>();
        ListNode index1 = headA;
        ListNode index2 = headB;
        while(index1 != null){
        	map.put(index1, map.getOrDefault(index1, 0) + 1);
        	index1 = index1.next;
        }
        while(index2 != null){
        	map.put(index2, map.getOrDefault(index2, 0) + 1);
        	index2 = index2.next;
        }
        ListNode index = headA;
        while(index != null){
        	if(map.get(index) == 2){
        		return index;
        	}
        	index = index.next;
        }
        return null;
    }
    /**
     * -主函数
     */
    public static void main(String[] args){
    	
    }
}
